// test_linkedlist_stack.cpp

#include <gtest/gtest.h>
#include "LinkedListStack.h"

// 基本操作测试
TEST(LinkedListStackTest, BasicOperations) {
    LinkedListStack s;

    EXPECT_TRUE(s.isEmpty());

    s.push(1);
    s.push(2);
    s.push(3);
    EXPECT_EQ(s.size(), 3);
    EXPECT_EQ(s.peek(), 3);
    EXPECT_FALSE(s.isEmpty());

    s.pop();
    EXPECT_EQ(s.size(), 2);
    EXPECT_EQ(s.peek(), 2);

    s.pop();
    s.pop();
    EXPECT_TRUE(s.isEmpty());
    EXPECT_EQ(s.size(), 0);
}

// 空栈测试
TEST(LinkedListStackTest, EmptyStackBehavior) {
    LinkedListStack s;

    EXPECT_TRUE(s.isEmpty());

    // 弹空栈，peek空栈，应有良好行为（假设peek返回-1或其他约定值）
    s.pop();  // 不应崩溃
    EXPECT_EQ(s.peek(), -1);  // 如果peek空栈返回-1
    EXPECT_EQ(s.size(), 0);
}

// 大数据量测试
TEST(LinkedListStackTest, LargeScaleOperations) {
    LinkedListStack s;
    const int N = 100000;

    for (int i = 0; i < N; ++i) {
        s.push(i);
    }
    EXPECT_EQ(s.size(), N);
    EXPECT_EQ(s.peek(), N - 1);

    for (int i = 0; i < N; ++i) {
        EXPECT_EQ(s.peek(), N - 1 - i);
        s.pop();
    }

    EXPECT_TRUE(s.isEmpty());
}

// 混合操作测试
TEST(LinkedListStackTest, MixedOperations) {
    LinkedListStack s;

    s.push(10);
    s.push(20);
    EXPECT_EQ(s.peek(), 20);
    s.pop();
    EXPECT_EQ(s.peek(), 10);
    s.push(30);
    EXPECT_EQ(s.peek(), 30);
    s.pop();
    s.pop();

    EXPECT_TRUE(s.isEmpty());
}

int main() {
    ::testing::InitGoogleTest();
    return RUN_ALL_TESTS();
}